import Vue from 'vue'
import Vuex from 'vuex'


Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    //登录框的状态
    isOpenLogin: false,
    modal: {
      //获取输出数据
      LogMsg: '',
      //提示框的状态
      isLoginMsg: false,
      icon: ""
    }


  },
  getters: {
  },
  mutations: {
    //登录框修改 状态 的方法
    changeIsLogin(state, payload) {
      state.isOpenLogin = payload
    },
    changeVal(state, payload) {
      state.modal.LogMsg = payload
    },
    //打开提示框组件 的方法
    changeIsLoginMsg(state, payload) {
      state.modal.isLoginMsg = true,
        state.modal.LogMsg = payload.LogMsg;
      switch (payload.icon) {
        case "info":
          state.modal.icon = "icon-toast-jinggao";
          break;
        case "success":
          state.modal.icon = "icon-toast_chenggong";
          break;
        case "danger":
          state.modal.icon = "icon-toast-shibai_huaban";
          break;
        case "loading":
          state.modal.icon = "icon-loading";
          break;
        default:
          state.modal.icon = "icon-toast-jinggao";
          break;
      }
    },
    // 同步关闭提示模态框
    closeModal(state) {
      state.modal.isLoginMsg = false
    }
  },
  actions: {
    AsyncModal({
      commit
    }, payload) {
      console.log(1);
      commit('changeIsLoginMsg', payload);
      setTimeout(() => {
        commit('closeModal')
      }, 2000)
    }
  },
  modules: {
  }
})
